package PeterSheep.StorageCenters;

import PeterSheep.AccountsManage.UBPlayer;

import java.util.ArrayList;

public class UBPlayerStorage {
    ArrayList<UBPlayer> BindPlayers = new ArrayList<UBPlayer>();

    public void addPlayerAccount(UBPlayer playerAccount) { this.BindPlayers.add(playerAccount); }
    public void delPlayerAccount(int playerAccountId) { this.BindPlayers.remove(playerAccountId); }

    public UBPlayer getPlayerFId(int playerAccountId) { return this.BindPlayers.get(playerAccountId); }
    public UBPlayer searchPlayerFGameName(String playerGameName) {
        for(UBPlayer target : this.BindPlayers) {
            if(target.getBindPlayer().getName().equals(playerGameName))
                return target;
        }

        return null;
    }

    public UBPlayer searchAccountFUsername(String accountUsername) {
        for(UBPlayer target : this.BindPlayers) {
            if(target.getBindAccount().username.equals(accountUsername))
                return target;
        }

        return null;
    }

    public int getIdFUsername(String accountUsername) {
        for(int i = 0; i < this.BindPlayers.size(); i++) {
            if(this.BindPlayers.get(i).getBindAccount().username.equals(accountUsername))
                return i;
        }

        return -255;
    }

    public int getIdFGameName(String playerGameName) {
        for(int i = 0; i < this.BindPlayers.size(); i++) {
            if(this.BindPlayers.get(i).getBindPlayer().getName().equals(playerGameName))
                return i;
        }

        return -255;
    }
}
